package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "菜品分类相关接口")
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {
   @Autowired
   private CategoryService categoryService;

    @GetMapping("/page")
    @ApiOperation("分页查询")
   public Result<PageResult> getPage(CategoryPageQueryDTO categoryPageQueryDTO){
        return categoryService.getPage(categoryPageQueryDTO);
   }


   @PostMapping
   @ApiOperation("新增菜品类别")
   public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.addCategory(categoryDTO);
        return Result.success();
   }
   @PostMapping("/status/{status}")
   @ApiOperation("启用或者禁用状态")
   public Result startOrStopStatus(@PathVariable Integer status,Long id){
        categoryService.startOrStopStatus(status,id);
        return Result.success();
   }

   @PutMapping
   @ApiOperation("修改分类")
   public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

   @DeleteMapping
   @ApiOperation("根据id删除类别")
   public Result deleteCategoryById(Long id){
        categoryService.deleteCategory(id);
        return Result.success();

   }

   @GetMapping("/list")
   @ApiOperation("根据类型查询")
   public Result<List<Category>> selectByType(Integer type){

       return Result.success(categoryService.selectByType(type));
   }






}
